<?php
namespace app\adminapiv3\service;

/**
 * @name: 主机接口逻辑层
 * @Param: 
 * @Description: 
 * @Author: foo
 * @Date: 2019-10-24 16:09:41
 */
use app\adminapiv3\service\attackLogManage\AttackLogService;
use app\common\service;
class Host extends Base
{
    private $remotePath = '/tmp/Install.sh';//远程安装路径
    /**
     * @name: 统计
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-11-20 14:56:05
     */
    function statistics ()
    {
        $Host = new service\Host();
        $return['os'] = $this->toDo([$Host, 'osStatistics']);//操作系统比率
        $return['tag'] = $this->toDo([$Host, 'tagStatistics']);//标签比率
        
        $HostView = new service\HostView();
        $return['top']['port'] = $this->toDo([$HostView, 'topPort']);//曲线 端口访问量

        return $return;
    }
    /**
     * @name: 列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-24 16:10:07
     */
    function list ($data, $limit)
    {
        $Host = new service\Host();

        $server = new AttackLogService();
        $data['id'] = $server->belongedHost();

        $return = $Host->list($data, $limit);


        $host_id_arr = $this->findGroupHost();
        foreach ($return['data'] as $k => $v){
            $return['data'][$k]['is_option'] = in_array($v['id'], $host_id_arr) ? 1 : 0;
        }

        return $return;
    }

    /**
     * @name: 列表处理
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-24 16:23:11
     */
    function processList ($data, $module)
    {
        if (empty($data))
        {
            return [];
        }
        $return = [];
        $serviceId_a = [];
        $addressId_a = [];
        $ministryId_a = [];
        $managerId_a = [];
        $softwareId_a = [];
        $offline = [];
        foreach ($data as  $k => $v) 
        {
            $hostId_a[] = $v['id'];
            $addressId_a[] = $v['address_id'];
            $ministryId_a[] = $v['ministry_id'];
            $managerId_a[] = $v['manager_id'];
            $softwareId_a[] = $v['software_id'];
            $serviceId_a[] = $v['safe_provider_id'];
            $serviceId_a[] = $v['develop_provider_id'];
            $serviceId_a[] = $v['maintain_provider_id'];
            $v['online'] == 0 ? $offline[] = $v['id'] : '' ;
        }
        if($module == 'netfilter')
        {
            $HostLearnConfig = new service\HostLearnConfig();
            $HostLearnConfig->autoStopLearn($offline);//停止自学习状态
        }
        $extraData = $this->extraData($serviceId_a, $managerId_a, $ministryId_a, $addressId_a, $softwareId_a, $hostId_a);
        $moduleData = $this->moduleData($module, $hostId_a);
        foreach ($data as $k => $v)
        {
            $return[$k] = $this->processOne($extraData, $v);
            !isset($moduleData[$v['id']]) ? : $return[$k][$module] = $moduleData[$v['id']];
        }

        return $return;
    }

    /**
     * @name: 模块数据
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-01-06 13:04:17
     */
    function moduleData ($module, $hostId_a)
    {
        if ($module == 'client')
        {
            return [];
        }
        $action = $module.'_config';
        $return = $this->$action($hostId_a);

        return $return;
    }

    /**
     * @name: netfilter 设置
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-01-06 13:05:54
     */
    function netfilter_config ($hostId_a)
    {
        $HostLearnConfig = new service\HostLearnConfig();
        $config = $HostLearnConfig->selectByHostId($hostId_a,'*');

        foreach ($config as $v)
        {
            $return[$v['host_id']] = [
                'init' => $v['init'],//是否初始化
                'firewall' => $v['firewall'],//防火墙
                'log_status' => $v['log_status'],//日志状态
                'learn_status' => $v['learn_status'],//学习状态
                'virtual_rule_hit_remind' => $v['virtual_rule_hit_remind'],//提醒是否有新的命中
                'study_config' => [
                    'stime' => $v['stime'],//学习开始时间
                    'etime' => $v['etime'],//学习结束时间
                    'keep_time' => $v['keep_time'],//学习持续时间
                    'auto' => $v['auto'],//是否自动
                    'model' => $v['model'],//学习模式
                    'allow' => $v['allow'],//默认处理方式
                    'have_mac_addr' => $v['have_mac_addr'],//默认处理方式
                    'now' => $v['now'],//默认处理方式
                ],
            ];
        }
        return $return;
    }

    /**
     * @name: 系统伪装模块设置
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-01-06 13:06:29
     */
    function disguise_config ($hostId_a)
    {
        $HostGuiseConfig = new service\HostGuiseConfig();

        $config = $HostGuiseConfig->selectByHostId($hostId_a);

        $HostGuisePort = new service\HostGuisePort();
        $port_a = $HostGuisePort->selectByHostId($hostId_a);
        $hostPort = [];
        foreach ($port_a as $port)
        {
            $hostPort[$port['host_id']]['port'][$port['type']][] = $port['port'];
        }

        $return = [];
        foreach ($config as $v)
        {
            
            $return[$v['host_id']]['port'] = [
                'middleware' => 0,
                'sql' => 0,
                'standard' => 0,
                'tcp' => '',
                'udp' => '',
            ];
            foreach($hostPort[$v['host_id']]['port'] as $type => $port)
            {
                $return[$v['host_id']]['port'][$type] = implode(',', $port);
            }
            $return[$v['host_id']]['guise_status'] = $v['guise_status'];
        }
        
        return $return;
    }

    /**
     * @name: 函谷盾设置
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-01-06 13:07:15
     */
    function hgshield_config ($hostId_a)
    {
        $IpsConfig = new service\IpsConfig();

        $config = $IpsConfig->selectByHostId($hostId_a,'type,black,firewall,protect_ip,device_ip,status,host_id');

        foreach ($config as $v)
        {
            $return[$v['host_id']] = $v;
        }

        return $return;
    }
    /**
     * @name: 额外的附属数据
     * @Param:
     * @Description:
     * @Author: foo
     * @Date: 2019-10-25 13:38:12
     */
    function extraData ($serviceId_a, $managerId_a, $ministryId_a, $addressId_a, $softwareId_a)
    {

        $hostManagerServer = new service\HostManager();
        $return['manager'] = $hostManagerServer->showManager($managerId_a, 'name,phone', 'id');

        $hostMinistryServer = new service\HostMinistry();
        $return['ministry'] = $hostMinistryServer->showMinistry($ministryId_a, 'id,pid,name', 'id');

        $hostAddressServer = new service\HostAddress();
        $return['address'] = $hostAddressServer->showAddress($addressId_a, 'id,name,address', 'id');

        $hostTagServer = new service\HostTag();
        $return['tag'] = $hostTagServer->showTag([], 'id,name,icon', 'id');

        $hostSoftwareServer = new service\HostSoftware();
        $return['software'] = $hostSoftwareServer->showSoftware($softwareId_a, 'id,name,status', 'id');

        $hostServiceServer = new service\HostService();
        $return['service'] = $hostServiceServer->showService($serviceId_a, 'id,name, contact, phone, status','id');

        return $return;
    }
    /**
     * @name: 单个处理
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-25 13:34:18
     */
    function processOne ($extraData, $data)
    {
        $params = [
            'id',//客户端id
            'name',//客户端名
            'alias',//客户端别名
            'ip',//客户端ip
            'dns',//dns
            'gateway',//网关
            'network_name',//网卡名
            'system_name',//系统名
            'os',//系统类别
            'online',//是否在线
            'version',//客户端/模块 版本号
        ];
        foreach ($params as $v)
        {
            isset($data[$v]) ? $return[$v] = $data[$v] : '';
        }
        $return['tag']= $this->processTag($extraData['tag'], $data['tag']);
        $return['software'] = $this->processSoftware($extraData['software'], $data['software_id']);//安全责任人
        $return['ministry'] = $this->processMinistry($extraData['ministry'], $data['ministry_id']);//安全责任人
        $return['address'] = $this->processAddress($extraData['address'], $data['address_id']);//安全责任人
        $return['manager'] = $this->processSafeManager($extraData['manager'], $data['manager_id']);//安全责任人
        $return['develop_provider'] = $this->processService($extraData['service'], $data['develop_provider_id']);//开发商
        $return['maintain_provider'] = $this->processService($extraData['service'], $data['maintain_provider_id']);//开发商
        $return['safe_provider'] = $this->processService($extraData['service'], $data['safe_provider_id']);//开发商

        return $return;
    }

    /**
     * @name: 添加标签
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-25 13:44:49
     */
    function processTag($tagData, $hostTag)
    {
        $return = [];
        if (empty($hostTag))
        {
            return $return;
        }
        
        $tag_a = explode(',',$hostTag);
        foreach ($tag_a as $tag_id)
        {
            if(isset($tagData[$tag_id]))
            {
                $return[] = [
                    'id' => $tagData[$tag_id]['id'],
                    'name' => $tagData[$tag_id]['name'],
                    'icon' => $tagData[$tag_id]['icon'],
                ];
            }
        }

        return $return;
    }

    /**
     * @name: 安全关管理员
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-25 14:05:11
     */
    function processSafeManager ($safeManagerData, $hostSafeManagerId)
    {
        $return = !isset($safeManagerData[$hostSafeManagerId]) ? [] : $safeManagerData[$hostSafeManagerId];

        return $return;
    }
    /**
     * @name: 地址
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-25 14:05:11
     */
    function processAddress ($addressData, $hostAddressId)
    {
        $return = !isset($addressData[$hostAddressId]) ? [] : $addressData[$hostAddressId];

        return $return;
    }
    /**
     * @name: 所属系统
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-25 14:05:11
     */
    function processSoftware ($softwareData, $hostSoftwareId)
    {
        $return = !isset($softwareData[$hostSoftwareId]) ? [] : $softwareData[$hostSoftwareId];

        return $return;
    }
    /**
     * @name: 部门
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-25 14:05:11
     */
    function processMinistry ($ministryData, $hostMinistryId)
    {
        $return = !isset($ministryData[$hostMinistryId]) ? [] : $ministryData[$hostMinistryId];

        return $return;
    }

    /**
     * @name: 处理服务商
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-25 13:59:21
     */
    function processService ($serviceData, $hostServiceId)
    {
        if (!isset($serviceData[$hostServiceId]))
        {
            return [];
        }

        $msg = '(合作已终止)';
        if($serviceData[$hostServiceId]['status'] == 2)
        {
            $serviceData[$hostServiceId]['name'] .= $msg;
            $serviceData[$hostServiceId]['contact'] .= $msg;
        }

        return $serviceData[$hostServiceId];
    }

    /**
     * @name: 处理运行中模块
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-25 14:58:43
     */
    function processRuningModule ($host_id)
    {
        $ServerAuth = new service\ServerAuth();
        $moduleList = $ServerAuth->moduleList();
        $moduleData = array_column($moduleList, 'module_name', 'product_key');
        $HostModuleRelation = new service\HostModuleRelation();
        $hostModule = $HostModuleRelation->findByHostId($host_id);

        $return = [];
        if (empty($hostModule))
        {
            return $return;
        }

        foreach ($hostModule as $k=>$v)
        {
            if(isset($moduleData[$k]) && $v == 1)
            {
                $return[] = $moduleData[$k];
            }
        }

        return $return;
    }

    /**
     * @name: 处理主机端口
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-25 15:56:59
     */
    function processPort ($host_id)
    {
        $HostPort = new service\HostPort();
        $data = $HostPort->toDo('list', [['host_id' => $host_id], 10]);
        $return = array_column($data['data'], 'port');

        return $return;
    }

    /**
     * @name: 主机详情
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-25 11:20:58
     */
    function detail ($host_id)
    {
        $return = $this->toDo('info', [$host_id]);
        $return['hardware']= $this->hardware($host_id);//主机硬件使用情况
        $return['runing_module'] = $this->processRuningModule($host_id);//主机运行模块
        $return['open_port'] = $this->processPort($host_id);//开放端口

        return $return;
    }

    /**
     * @name: 添加主机
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-29 10:27:42
     */
    function add ($hostData, $contactData)
    {
        $HostContact = new service\HostContact();
        $HostContact->toDo('ipNotExist',[$contactData['ip']]);//检测ip 是否存在

        $Host = new service\Host();
        $host_id = $Host->toDo('add', [$hostData]);//添加主体
        $contactData['host_id'] = $host_id;
        $HostContact->toDo('add', [$contactData]);//添加ssh登陆表
        $HostHardware = new service\HostHardware();
        $HostHardware->toDo('add', [$host_id]);//添加硬件
        $HostModuleRelation = new service\HostModuleRelation();
        $HostLink = new service\HostLink();
        $HostLink->toDo('add', ['client', [$host_id]]);
        $HostModuleRelation->toDo('init', [$host_id]);//模块关系表初始化
        $this->toDo('installClient', [$contactData]);//ssh连接服务器安装客户端

        return $host_id;
    }

    /**
     * @name: 修改
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-29 11:26:50
     */
    function modify ($hostData)
    {
        $Host = new service\Host();
        $this->toDo([$Host, 'modify'], [['id' => $hostData['id']], $hostData]);//修改

    }

    /**
     * @name: 删除/批量删除
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-29 13:18:03
     */
    function uninstall ($host_id)
    {
        //验证
        $this->checkOptionHost($host_id);

        $hostList = $this->getHost();

        $return = array_filter($hostList, function($v){
            if($v['os'] > 0)
            {
                return $v;
            }
        });


        $host_id = array_column($hostList, 'id');

        //验证是否有硬件版
        $hardwareCount = db('host')->whereIn('id', $host_id)->where('is_software', 0)->count();

        if($hardwareCount > 0){
            $this->setError($this->CODE_FAIL, '不能删除硬件版主机');

            return false;
        }

        $Host = new service\Host();
        $Host->uninstall($host_id);

        $HostModuleRelation = new service\HostModuleRelation();
        $HostModuleRelation->uninstall($host_id);

        $moduleId = db('server_auth_module')->where('module_key', 'client')->value('id');
        //修改授权数量
        foreach ($hostList as $hostId => $v){

            db('server_user_group_module')
                ->where('group_id', $v['group_id'])
                ->where('module_id', $moduleId)
                ->setDec('used', 1);
        }

        return $return;
    }

    /**
     * @name: 详情
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-29 13:28:10
     */
    function info ($host_id)
    {
        $Host = new service\Host();
        $data = $Host->toDo('info',[$host_id]);

        $serviceId_a = [
            $data['safe_provider_id'],
            $data['develop_provider_id'],
            $data['maintain_provider_id'],
        ];

        $extraData = $this->extraData($serviceId_a, $data['manager_id'], $data['ministry_id'], $data['address_id'], $data['software_id']);
        $return = $this->processOne($extraData, $data);

        return $return;
    }

    /**
     * @name: 主机硬件使用
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-29 14:21:34
     */
    function hardware ($host_id)
    {
        $HostHardware = new service\HostHardware();
        $data = $HostHardware->findOne($host_id);

        $return = [];
        if(!empty($data['info']))
        {
            $return = json_decode($data['info'],true);
        }

        return $return;
    }

    /**
     * @name: 检测是否安装
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-29 15:18:06
     */
    function checkClient ($contactData)
    {
        $HostContact = new service\HostContact();
        $this->toDo([$HostContact, 'ipNotExist'],[$contactData['ip']]);

        $filePath = $this->toDo('checkInstallPackage');

        if($contactData['type'] == 2)
        {
            $SSH = new SSH($contactData['ip'], $contactData['user'], $contactData['password'], $contactData['port']);
            $SSH->toDo('sendFile', [$filePath, $this->remotePath]);
        }
    }

    /**
     * @name: ssh 安装客户端
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-06-13 16:35:36
     */
    function installClient ($contactData)
    {
        if ($contactData['type'] == 1) {
            return false;
        }

        $SSH = new SSH($contactData['ip'], $contactData['user'], $contactData['pwd'], $contactData['port']);
        $serverIp = $_SERVER['SERVER_ADDR'];
        $sftp = ssh2_sftp($SSH->conn);
        if(!file_exists("ssh2.sftp://{$sftp}/" . $this->remotePath))
        {
            $this->setError($this->CODE_FAIL, $serverIp . '未找到安装包');
            return false;
        }
        
        $cmd1 = '[ `id -u` -eq 0 ] && { chmod +x ' . $this->remotePath . ' && ' . $this->remotePath . ' -s ' . $serverIp . ' ; } || { which sudo && echo ' . $contactData['pwd'] . ' | sudo -s  ' . $this->remotePath . ' && sudo -s ' . $this->remotePath .' -s ' . $serverIp . ' ; }';
        $SSH->toDo('exec', [$cmd1]);
        $cmd2 = 'echo ' . "'". $cmd1 ."'" . ' >> /tmp/install_cmd.txt';
        $SSH->toDo('exec', [$cmd2]);

    }

    /**
     * @name: 筛选数据
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-30 10:41:16
     */
    function filterData ()
    {
        $server = new service\Host();
        $hostArr = $server->filterData();

        return $hostArr;
    }

    /**
     * @name: 端口列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-11-01 15:05:58
     */
    function portList ($filterData, $limit)
    {
        $HostPort = new service\HostPort();
        $return = $HostPort->toDo('list', [$filterData, $limit]);

        return $return;
    }

    /**
     * @name: 重新安装
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-11-15 15:56:09
     */
    function reinstall ()
    {
        $host_id = $this->getHost('id', 'string');
        
        $Host = new service\Host();

        $host = $Host->findById($host_id);
        if (empty($host))
        {
            $this->setError($this->CODE_FAIL, '主机不存在');
            return false;
        }

        if($host['os'] != 0)
        {
            $this->setError($this->CODE_FAIL, '主机已存在');
            return false;
        }

        $HostContact = new service\HostContact();
        $contactData = $HostContact->findData(['host_id'=>$host_id]);

        $this->toDo('installClient', [$contactData]);
        
    }

    /**
     * @name: 检查安装包
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-01-06 18:06:03
     */
    function checkInstallPackage ()
    {
        $ServerDownload = new ServerDownload();
        $fileData = $ServerDownload->moduleFilePath;
        if (!file_exists($fileData['4']))
        {
            $this->setError($this->CODE_FAIL, '未找到指定安装包，请联系管理员处理');
            return false;
        }

        $return = $fileData['4'];

        return $return;
    }


    /**
     * @name 开始查杀
     * @param $hostId
     * @return bool
     * @author wx
     * @date 2020/4/26 16:44
     */
    function fillKillStart($hostId)
    {
        $this->checkOptionHost($hostId);

        $WebsiteProtect = new service\IpsWebsiteProtect();
        //查找信息
        if($WebsiteProtect->havProtect($hostId) == 0)
        {
            $this->setError($this->CODE_FAIL, '没有找到需要扫描的目录,请先设置防篡改策略!');
            return false;
        }

        $HostFileScreening = new service\HostFileScreening();
        $HostFileScreening->start($hostId);

        return true;
    }

    /**
     * @name 停止文件查杀
     * @param $hostId
     * @return bool
     * @author wx
     * @date 2020/4/26 16:59
     */
    function fillKillStop($hostId)
    {
        $this->checkOptionHost($hostId);

        if (empty($hostId))
        {
            $this->setError($this->CODE_FAIL,'参数错误');
            return false;
        }

        $HostFileScreening = new service\HostFileScreening();
        $HostFileScreening->stop($hostId);

        //调用中间件接口
        return true;
    }

    /**
     * @name 查看查杀状态
     * @param $hostId
     * @return bool
     * @author wx
     * @date 2020/4/26 17:08
     */
    function fileKillRunStatus($hostId)
    {
        if (empty($hostId))
        {
            $this->setError($this->CODE_FAIL,'参数错误');
            return false;
        }

        //1. 查询文件查杀
        $HostFileScreening = new service\HostFileScreening();
        $return = $HostFileScreening->runStatus($hostId);


        //2. 查询文件攻击
        $log = db('file_attack')
            ->where('host_id', $hostId)
            ->where('source',2)
            ->where('ctime', '>=', $return['stime'])
            ->select();

        $handleArray = array(
            1 => '已隔离',
            0 => '未隔离',
        );

        foreach ($log as $k => $v){
            $return['log'][] = $v['path'] . ' ' . $handleArray[$v['handle']] . ' 该文件用于运行或执行客户端传递的功能代码模块';
        }


        return $return;

    }

    /**
     * @name 文件查杀继续
     * @param $hostId
     * @return array|bool|null|\PDOStatement|string|\think\Model
     * @author wx
     * @date 2020/4/26 17:34
     */
    function fileKillContinue($hostId)
    {
        if (empty($hostId))
        {
            $this->setError($this->CODE_FAIL,'参数错误');
            return false;
        }

        $HostFileScreening = new service\HostFileScreening();
        $HostFileScreening->continue($hostId);
    }

    /**
     * @name 暂停
     * @param $hostId
     * @return bool
     * @author wx
     * @date 2020/4/26 17:42
     */
    function fileKillPause($hostId)
    {
        if (empty($hostId))
        {
            $this->setError($this->CODE_FAIL,'参数错误');
            return false;
        }

        $HostFileScreening = new service\HostFileScreening();
        $HostFileScreening->pause($hostId);
    }

    /**
     * @name 运行状态
     * @param int $id
     * @return array|null|\PDOStatement|string|\think\Model|void
     * @Author wx
     * @date 2019/8/14 14:08
     */
    function runStatus($host_id = 0)
    {
        if(empty($host_id))
        {
            $this->setError($this->CODE_FAIL,'参数错误');
            return false;
        }

        $server = new \app\common\service\HostHardware();
        $info = $server->findOne($host_id);

        if(!$info){
            $this->setError($this->CODE_FAIL,'数据错误');
            return false;
        }
        $hardwareUsed = json_decode($info['info'],true);

        $data['id'] = $info['host_id'];
        $data['memory'] = isset($hardwareUsed['Memory']) ? $hardwareUsed['Memory'] : 0;
        $data['cpu'] = isset($hardwareUsed['Cpu']) ? $hardwareUsed['Cpu'] : 0;
        $data['disk'] = isset($hardwareUsed['Disk']) ? $hardwareUsed['Disk'] : 0;
        $data['time'] = date('H:i:s', time());

        return $data;
    }

    /**
     * @name 主机详情
     * @param $host_id
     * @author wx
     * @date 2020/5/10 10:28
     */
    function hostInfo($host_id)
    {
        if(empty($host_id))
        {
            $this->setError($this->CODE_FAIL,'参数错误');
            return false;
        }

        $field = 'h.id,h.name,h.ip,h.description,h.is_software,
        hs.host_id, hs.auto_defense, hs.shell_defense, hs.shell_defense_handle,
        hs.shell_defense_level, hs.illegal_modify, hs.file_safe,hs.empowerment,
        ic.status, ic.type, ic.black, ic.firewall, ic.protect_ip, ic.device_ip,ic.csrf';
        $server = new \app\common\service\Host();
        $info = $server->getHostINfo(['h.id' => $host_id], $field);

        return $info;
    }

    /**
     * @name 修改
     * @param int $host_id
     * @param array $host
     * @param array $hostStatus
     * @return bool
     * @author wx
     * @date 2020/5/10 10:44
     */
    function descritionModify($host_id = 0, $host = array())
    {
        $this->checkOptionHost($host_id);

        if(empty($host_id))
        {
            $this->setError($this->CODE_FAIL,'参数错误');
            return false;
        }
        //修改host表数据
        $hostServer = new \app\common\service\Host();
        $hostServer->modify(['id' => $host_id], $host);

        return true;
    }

    /**
     * @name 配置defense修改
     * @author wx
     * @date 2020/6/24 9:27
     */
    function hostStatusModify($host_id = 0, $hostStatus = array())
    {
        $this->checkOptionHost($host_id);

        //修改host_status表数据
        $hostStatusServer = new service\HostStatus();
        $hostStatusServer->modify(['host_id' => $host_id], $hostStatus);
    }

    /**
     * @name 修改wipf设置
     * @author wx
     * @date 2020/6/24 11:01
     */
    function ipsConfigModify($host_id, $configData)
    {
        $this->checkOptionHost($host_id);

        $hostStatusServer = new service\IpsConfig();
        $hostStatusServer->modify(['host_id' => $host_id], $configData);
    }

    /**
     * @name 客户端下载
     * @return mixed
     * @author wx
     * @date 2020/9/1 9:47
     */
    function clientDownload()
    {
        //获取用户绑定key
        $userGroupId = $this->getUserInfo('user_group_id');

        $bindKey = db('server_user_group')->where('id', $userGroupId)->value('bind_key');

        return $bindKey;
    }
}